﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
 ●版本：1.0
**********************************************************/
using System.Data.Common;

namespace Smartkernel.Data
{
    /// <summary>
    /// Sql命令类。目的是将Sql语句与参数进行包装。如果将多个SmartSqlCommandLine对象打包为列表传地给执行方法，列表内的Sql将是按事务方式执行的。
    /// </summary>
    public class SmartSqlCommandLine
    {
        private string sqlSentence;
        /// <summary>
        /// Sql语句
        /// </summary>
        public string SqlSentence
        {
            get
            {
                return this.sqlSentence;
            }
        }
        private string error = string.Empty;
        /// <summary>
        /// 事务回滚时的错误消息
        /// </summary>
        public string Error
        {
            get
            {
                return this.error;
            }
        }
        private DbParameter[] parameters;
        /// <summary>
        /// Sql语句对应的参数数组
        /// </summary>
        public DbParameter[] Parameters
        {
            get
            {
                return this.parameters;
            }
        }
        private SmartRollbackCondition smartRollbackCondition;
        /// <summary>
        /// 事务回滚的条件
        /// </summary>
        public SmartRollbackCondition SmartRollbackCondition
        {
            get
            {
                return this.smartRollbackCondition;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sqlSentence">Sql语句</param>
        /// <param name="error">事务回滚时的错误消息</param>
        public SmartSqlCommandLine(string sqlSentence, string error)
            : this(sqlSentence, null, null, error)
        {

        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sqlSentence">Sql语句</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="error">事务回滚时的错误消息</param>
        public SmartSqlCommandLine(string sqlSentence, DbParameter[] parameters, string error)
            : this(sqlSentence, parameters, null, error)
        {

        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sqlSentence">Sql语句</param>
        /// <param name="smartRollbackCondition">事务回滚的条件</param>
        /// <param name="error">事务回滚时的错误消息</param>
        public SmartSqlCommandLine(string sqlSentence, SmartRollbackCondition smartRollbackCondition, string error)
            : this(sqlSentence, null, smartRollbackCondition, error)
        {

        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sqlSentence">Sql语句</param>
        /// <param name="parameters">参数数组</param>
        /// <param name="smartRollbackCondition">事务回滚的条件</param>
        /// <param name="error">事务回滚时的错误消息</param>
        public SmartSqlCommandLine(string sqlSentence, DbParameter[] parameters, SmartRollbackCondition smartRollbackCondition, string error)
        {
            this.sqlSentence = sqlSentence;
            this.parameters = parameters;
            this.smartRollbackCondition = smartRollbackCondition;
            this.error = error;
        }
    }
}
